package com.hdu.dwh.pojos.model_pojos;
import java.time.LocalDateTime;
import java.util.Set;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.hdu.dwh.pojos.source_access_pojos.DataWarehouseTable;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
 * 模型中的表
 */
/**
 * CREATE TABLE IF NOT EXISTS meta_table (
    id INT AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
    name VARCHAR(255) NOT NULL COMMENT 'meta表名',
    -- 一个模型关联一个事实表
    model_id INT NOT NULL COMMENT '模型ID',

    type ENUM('fact', 'dimension') NOT NULL COMMENT '表类型，fact表示事实表，dimension表示维度表',

    -- 事实表从原始表中得来，可以用作数据血缘
    source_table_id INT NOT NULL COMMENT ' 源表ID，指向原始表的ID',


    description TEXT COMMENT 'meta表描述',
    owner_id INT DEFAULT NULL COMMENT '所有者ID',
    project_id INT DEFAULT NULL COMMENT '项目ID',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
) COMMENT 'meta表';
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MetaTable {

    public MetaTable(DataWarehouseTable sourceTable, String type, Long modelId) {
        this.name = sourceTable.getTableName();
        this.type = type;
        this.sourceTableId = sourceTable.getId();
        this.modelId = modelId.intValue();
        this.description = sourceTable.getDescription();
    }

    @TableId(type = IdType.AUTO)
    @Schema(hidden = true)
    private Long id;

    @TableField("name")
    @Schema(hidden = true)
    private String name;

    @Schema(hidden = true)
    private Integer modelId;

    @TableField(exist = false)
    private Set<MetaColumn> columns;

    @Schema(hidden = true)
    private String type;

    private Long sourceTableId;

    @Schema(hidden = true)
    private String description;


    // private Integer ownerId;

    // private Integer projectId;

    @Schema(hidden = true)
    private LocalDateTime createdAt;

    @Schema(hidden = true)
    private LocalDateTime updatedAt;
    
}
